# Contributor: Isaac Dunham <ibid.ag@gmail.com>
# Maintainer:  Isaac Dunham <ibid.ag@gmail.com>
pkgname=xpdf
pkgver=4.02
pkgrel=0
pkgdesc="The classic X11 PDF viewer"
url="https://www.xpdfreader.com"
arch="all"
license="GPL-2.0-or-later OR GPL-3.0-or-later"
depends="ghostscript-fonts"
makedepends="cmake qt5-qtbase-dev"
subpackages="$pkgname-doc"
source="https://xpdfreader-dl.s3.amazonaws.com/xpdf-$pkgver.tar.gz
	permissions.patch"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake  -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_C_FLAGS="$CMAKE_C_FLAGS -fPIC" \
		-DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS -fPIC" \
		-DSYSTEM_XPDFRC=/etc/xpdfrc \
		$CMAKE_CROSSOPTS
	make -C build
}

package() {
	make -C build DESTDIR="$pkgdir" install

	# delete pdf* utils and associated man pages that conflict with
	# poppler-utils.
	rm -f "$pkgdir"/usr/bin/pdf*
	rm -f "$pkgdir"/usr/share/man/man1/pdf*

	# install xpdfrc
	install -Dm644 doc/sample-xpdfrc "$pkgdir"/etc/xpdfrc
}

sha512sums="72c9413fc7241dde5288137ca8a68c837d2a68e95e909dbe2afe8f374b5a7c92af4edf82918963d1c6388c947057fcf5f0ae1e6fbb2b31c3d5eb9a07d3c74ddc  xpdf-4.02.tar.gz
cf56bf9b4ccecc85fd34805454513b921bfe044442dad129178cde6f9ff2fae322bf0d71aaa69b9456aa0f41d639bc3a6aa2c7dcaae177013ac45e92f9fc3125  permissions.patch"
